﻿using DevExpress.Utils;
using DevTeam;

using System;
using System.Drawing;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo.Kauf
{
    public partial class KaufInvoice : XPopupForm
    {
        public KaufInvoice(int idx,int customerId)
        {
            InitializeComponent();
            CustomerId = customerId;
            Idx = idx;
            TAM.PlanlamaLinesInvoiceTableAdapter = new Datasets.MyDataTableAdapters.PlanlamaLinesInvoiceTableAdapter();
        }
        BindingSource bsInvoice;
        int PlanlamaLinesId,Idx,CustomerId;
        private void Fatura_Load(object sender, EventArgs e)
        {
            
            GetDetails("PlanlamaLinesInvoice", "GetPlanlamaLinesInvoiceByKaufIdx",Idx,CustomerId);
            bsInvoice = new BindingSource(ds, "PlanlamaLinesInvoice");
            InitGridView(gvInvoice, bsInvoice);
            gvInvoice.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;

            if (ds.Tables["Table1"].Rows.Count > 0)
            {
                PlanlamaLinesId = ds.Tables["Table1"].Rows[0][0].ToInt(-1);
                gvInvoice.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
                gvInvoice.BestFitColumns();
                foreach (string str in "PlanlamaLinesInvoiceId;PlanlamaLinesId".Split(';'))
                    gvInvoice.Columns[str].Visible = false;

                gvInvoice.AddSummary("YuklenenAdet", "Yuklenen2Kalite");
                gvInvoice.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gridView1_RowCellStyle);
                btnOK.ItemClick += btnOK_ItemClick;
                ds.PlanlamaLinesInvoice.TableNewRow += new System.Data.DataTableNewRowEventHandler(PlanlamaLinesInvoice_TableNewRow);
            }
        }

        void btnOK_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Save();
            this.DialogResult = DialogResult.OK;
        }

        void PlanlamaLinesInvoice_TableNewRow(object sender, System.Data.DataTableNewRowEventArgs e)
        {
            e.Row["PlanlamaLinesId"] = PlanlamaLinesId;
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle >= 0)
                if (e.Column.FieldName == "YuklenenAdet")
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
        }

    }
}